const { src, dest, lastRun } = require('gulp')
const terser = require('gulp-terser')
const gulpif = require('gulp-if')
const cssmin = require('gulp-cssmin')
const buble = require('gulp-buble')

const srcDir = 'public/libs/**/*'
const destDir = 'ccas-ui/libs/'

const isJs = file => file.extname === '.js'
const isCss = file => file.extname === '.css'

function defaultTask () {
  return src(srcDir, { since: lastRun(defaultTask) })
    .pipe(gulpif(isJs, buble({ objectAssign: true })))
    .pipe(gulpif(isJs, terser()))
    .pipe(gulpif(isCss, cssmin()))
    .pipe(dest(destDir))
}

exports.default = defaultTask
